package com.example.hcd.adapt;

import java.text.DecimalFormat;
import java.util.ArrayList;

import com.example.hcd.R;
import com.example.hcd.datamanage.ReimburseData;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ReimburseListAdapt extends BaseAdapter{
	private ArrayList<ReimburseData> myItemList = new ArrayList<ReimburseData>();
	private Context context;
	private LayoutInflater mInflate;
	private boolean isLookDeatail=false;
	public ReimburseListAdapt(Context context) {
		// TODO Auto-generated constructor stub
		this.context = context;
		mInflate = LayoutInflater.from(context);
	}
	
	public void setisLookDetail(boolean islook)
	{
		isLookDeatail = islook;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return myItemList.size();
	}

	@Override
	public ReimburseData getItem(int position) {
		// TODO Auto-generated method stub
		return myItemList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			convertView = mInflate.inflate(R.layout.my_reimburse_item, null);
            
        }
		ReimburseData date = getItem(position);
		TextView text;
		LinearLayout view = (LinearLayout)convertView.findViewById(R.id.line111);
		if(isLookDeatail)
		{
			view.setVisibility(View.GONE);	
		}else
		{
			text = (TextView) convertView.findViewById(R.id.name_dep);
			text.setText(date.getApplicant());
		}
		

		text = (TextView) convertView.findViewById(R.id.title);
		text.setText(date.getTitle());

		text = (TextView) convertView.findViewById(R.id.project_name);
		view = (LinearLayout)convertView.findViewById(R.id.line311);
		if(isLookDeatail)
		{
			view.setVisibility(View.GONE);	
		}else
		text.setText(date.getProcessStatus());

		text = (TextView) convertView.findViewById(R.id.amount_money);
		DecimalFormat nf = new DecimalFormat("#0.00");
		nf.setGroupingUsed(false);
		text.setText(nf.format(date.getAmount()));

		text = (TextView) convertView.findViewById(R.id.create_time);
		text.setText(date.getCreatetime());
		
		if(isLookDeatail)
		{
			ImageView icon = (ImageView)convertView.findViewById(R.id.status_icon);
			icon.setVisibility(View.GONE);
		}else if(processStatus(date.getProcessStatusValue())!=-1)
		{
			ImageView icon = (ImageView)convertView.findViewById(R.id.status_icon);
			
			icon.setImageResource(processStatus(date.getProcessStatusValue()));
		}
		
		  return convertView;     
	}
	public int processStatus(String processStatusValue) {
		int processStatus = -1;
		switch (Integer.parseInt(processStatusValue)) {
		case 0:
//			尚未开始 0
//			进行中 1
//			未签收 2
//			办理中 3
//			已结束 9
			processStatus = R.drawable.submit02;
			break;
		case 1:
			processStatus = R.drawable.submit04;
			break;
		case 2:
			processStatus = R.drawable.submit04;
			break;
		case 3:
			processStatus = R.drawable.submit04;
			break;
		case 9:
			processStatus = R.drawable.submit03;
			break;

		default:
			break;
		}
		
		return processStatus;

	}
	
	public void setList(ArrayList<ReimburseData> list) {
        if (myItemList != null) {
        	myItemList.clear();
        	myItemList.addAll(list);
        } else {
        	myItemList = list;
        }
//        notifyDataSetInvalidated();
        notifyDataSetChanged();
    }
	
	public void addList(ArrayList<ReimburseData> lists)
	{
		myItemList.addAll(lists);
		
	}
}
